import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import New from '../views/nav/New.vue'
import Management from '../views/nav/Management.vue'
import Projects from '../views/nav/Projects.vue'
import DesignSystem from '../views/nav/DesignSystem.vue'
import Dynamic from '../views/nav/Dynamic.vue'
import Login from '../views/login/Login.vue'
import Register from '../views/login/Register.vue'
import GraphDesign from '../views/nav/GraphDesign.vue'
import Recycle from '../views/nav/Recycle.vue'
//import EditFile from '../views/nav/EditFile.vue'
import mainPage from '../views/main/mainPage.vue'
import Welcome from '../views/nav/welcome.vue'
import Personal from '../views/person/Personal.vue'
import Home from '../views/Home.vue'
import FileCenter from '../views/nav/FileCenter.vue'
import UML from '../views/nav/UML.vue'
//import Home from '../views/nav/Home.vue'
//import defaultHome from '../views/defaultHome.vue'
Vue.use(VueRouter)




const routes = [
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    redirect: '/welcome',
    children: [{path: '/welcome', component: Welcome},
               {path: '/new', component: New},
               {path: '/management', component: Management},
               {path: '/projects', component: Projects},
               {path: '/designSystem', component: DesignSystem},
               {path: '/dynamic', component: Dynamic},
               {path: '/graphdesign',component:GraphDesign},
               {path: '/recycle',component:Recycle},
               {path:'/filecenter',component:FileCenter},
               {path:'/uml',component:UML},
               {path:'/personal',component:Personal}]
  },
  {
    path: '/',
    redirect: '/mainPage'
  },
  {
    path: '/about',
    name: 'about',
        component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
  //将页面路由加入到路由列表中
  // {
  //   path: '/new',
  //   name: 'new',
  //   component:New
  // },
  // {
  //   path: '/management',
  //   name: 'management',
  //   component: Management
  // },
  // {
  //   path:'/projects',
  //   name:'projects',
  //   component:Projects
  // },
  // {
  //   path:'/designSystem',
  //   name:'designSystem',
  //   component:DesignSystem
  // },
  // {
  //   path:'/dynamic',
  //   name:'dynamic',
  //   component:Dynamic
  // },
  {
    path:'/login',
    name:'login',
    component:Login
  },
  {
    path:'/register',
    name:'register',
    component:Register
  },
  {
    path:'/mainpage',
    name:'mainpage',
    component:mainPage
  },
  {
    path:'/personal',
    name:'personal',
    component:Personal
  },
  {
    path:'/home1',
    name:'home1',
    component:() => import('@/views/Home'),
  }
  
  // {
  //   path:'/home',
  //   name:'home',
  //   component:Home,
  //   children:
  //   [{path:'new',component:New},
  //   {path:'designSystem',component:DesignSystem},
  //   {path:'dynamic',component:Dynamic},
  //   {path:'/',component:defaultHome},//默认页面
  //   {path:'management',component:Management},
  //   {path:'projects',component:Projects}

  // ]
  // }
  
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// //挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//   // to 将要访问的路径
//   // from 从哪个路径跳转而来
//   // next 是一个函数，表示放行
//   // next() 放行 next('/login') 强制跳转

//   if(to.path === '/login' || to.path === '/register' ){
//     return next();   //登录、注册页面放行
//   };
//   // 获取user
//   const userStr = window.localStorage.getItem('user');
//   const groupStr = window.localStorage.getItem('group');
//   const projectStr = window.localStorage.getItem('project');
//   if (!userStr) {
//     return next('/login');
//   } 
//   else if (!groupStr) {
//     if (to.path === '/about' || to.path === '/login' || to.path === '/register'){
//       return next(); //登录后，选择团队、登录、注册放行
//     }
//     return next('/about');
//   }
//   else if (!projectStr) {
//     if (to.path === '/about' || to.path === '/login' 
//     || to.path === '/register' || to.path === '/welcome'
//     || to.path === '/projects' || to.path === '/management'
//     || to.path === '/recycle'  || to.path==='/mainpage'
//     || to.path==='/personal'){
//       return next(); //选择团队后，项目管理、成员管理、回收站、选择团队、登录、注册放行
//     }
//     return next('/home');
//   }
//   next();
// })

export default router
